// application specific javascript config 
//params will be rendered here
ApplicationConfiguration = new function(){
	
	var properties = [];
	var observers = new org.jaxson.util.collections.Map();
	var contextPath = "<%= request.getContextPath() %>";
	
	// expose the context path as a property
	properties["context.path"] = contextPath;
	
	//<%= org.jaxson.config.ApplicationConfiguration.getInstance().asJavascript() %>
	
	if( window["console"] ){
		console.log( "application configuration:" );
		
		if( console["dir"] )
			console.dir( properties );
	}
	
	var fire = function( name, props ){
		var list = observers.get(name);
		
		if( list != null ){
			var value = props[name];
			
			for( i=0; i<list.size(); i++ ){
				list.get(i)(name, value);
			}
		}
	};
	
	var that = {
		setProperty : function( name, value ){
			properties[name] = value;
			fire( name, properties );
		},
		
		getProperty : function( name ){
			return properties[name];
		},
		
		setProperties : function( props ){
			propertes = props;
			properties["context.path"] = contextPath;
			
			for( name in props ){				
				fire( name, props );
			}
		},
		
		addObserver : function(name, func){
			
			if( observers.get(name) === null )
				observers.put( name, new org.jaxson.util.collections.List() );
			
			list = observers.get( name );
			list.add(func);
		},
		
		initialize : function(bus){
			var subscriber = function( event ){
				that.setProperties( event.configuration );
			}
			
			bus.subscribe( "<%=org.jaxson.struts.appconfig.ApplicationConfigurationEvent.EVENT_NAME%>", subscriber );
			delete this.initialize;
		}
	};
	
	return that;
};
